/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hibernate;

import com.partaljevic.gambling.beans.Match;
import com.partaljevic.tapestry.gambling.service.MatchesService;
import java.io.Serializable;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;

/**
 *
 * @author Nemanja
 */
public class MatchServiceHibernate implements MatchesService{

    private final Session session;

    public MatchServiceHibernate(Session session) {
        this.session = session;
    }

    @Override
    public void save(Match match) {
        session.save(match);
    }

    @Override
    public List<Match> retreive() {
        Criteria criteria = session.createCriteria(Match.class);
        return criteria.list();
    }

    @Override
    public Match retreive(Serializable id) {
        return (Match) session.get(Match.class, id);
    }

    @Override
    public void update(Match match) {
        session.saveOrUpdate(match);
    }

}
